// API服务
const API_BASE_URL = process.env.REACT_APP_API_BASE_URL || 'http://localhost:3001/api';

// 情绪分析API
export const analyzeEmotion = async (text: string) => {
  const response = await fetch(`${API_BASE_URL}/emotion`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ text }),
  });

  if (!response.ok) {
    throw new Error('情绪分析失败');
  }

  return response.json();
};

// 生成背景图片API
export const generateImage = async (text: string, emotion: string) => {
  const response = await fetch(`${API_BASE_URL}/generate-image`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ text, emotion }),
  });

  if (!response.ok) {
    throw new Error('图片生成失败');
  }

  return response.json();
};